﻿<%@ Application Language="C#" %>
<script RunAt="server">

    void Application_Start(object sender, EventArgs e)
    {
        //// Code that runs on application startup
        ////定义定时器 
        //System.Timers.Timer myTimer = new System.Timers.Timer(5000);
        //myTimer.Elapsed += new System.Timers.ElapsedEventHandler(myTimer_Elapsed);
        //myTimer.Enabled = true;
        //myTimer.AutoReset = true;

    }

    void Application_End(object sender, EventArgs e)
    {
        ////  Code that runs on application shutdown
        //TQB.Plugin.Log.Log.SaveNote(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":Application End!");

        ////下面的代码是关键，可解决IIS应用程序池自动回收的问题
        //System.Threading.Thread.Sleep(1000);
        ////这里设置你的web地址，可以随便指向你的任意一个aspx页面甚至不存在的页面，目的是要激发Application_Start
        //string url = "http://localhost:1868/" + "task.aspx";
        //System.Net.HttpWebRequest myHttpWebRequest = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create(url);
        //System.Net.HttpWebResponse myHttpWebResponse = (System.Net.HttpWebResponse)myHttpWebRequest.GetResponse();
        //System.IO.Stream receiveStream = myHttpWebResponse.GetResponseStream();             //得到回写的字节流
    }

    void Application_Error(object sender, EventArgs e)
    {
        // Code that runs when an unhandled error occurs

    }

    void Session_Start(object sender, EventArgs e)
    {
        // Code that runs when a new session is started
    }

    void Session_End(object sender, EventArgs e)
    {
        // Code that runs when a session ends. 
        // Note: The Session_End event is raised only when the sessionstate mode
        // is set to InProc in the Web.config file. If session mode is set to StateServer 
        // or SQLServer, the event is not raised.
    }

    void myTimer_Elapsed(object source, System.Timers.ElapsedEventArgs e)
    {
        try
        {
            TQB.Plugin.Log.Log.SaveNote(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":AutoTask is Working!");
            YourTask();
        }
        catch (Exception ee)
        {
            TQB.Plugin.Log.Log.SaveException(ee);
        }
    }

    void YourTask()
    {
        //在这里写你需要执行的任务

    }
       
</script>
